﻿using Prism.Commands;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ModuleA.ViewModels
{
	internal class ViewCViewModel : IDialogAware
	{
		public string Title { get; set; } = "对话框服务";

		public string P1 { get; set; }

		public event Action<IDialogResult> RequestClose;

		/// <summary>
		/// 确定命令
		/// </summary>
		public DelegateCommand ConfirmCmm { get; set; }

		public DelegateCommand CancelCmm { get; set; }

		public ViewCViewModel()
		{
			ConfirmCmm = new DelegateCommand(Confirm);
			CancelCmm = new DelegateCommand(Cancel);
		}

		private void Cancel()
		{
			RequestClose?.Invoke(new DialogResult(ButtonResult.No));
		}

		private void Confirm()
		{
			DialogParameters paras = new DialogParameters();
			paras.Add("result1", "返回值1：张三");
			paras.Add("result2", "返回值2：李四");
			RequestClose?.Invoke(new DialogResult(ButtonResult.OK, paras));
		}


		/// <summary>
		/// 是否能够关闭对话框
		/// </summary>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		public bool CanCloseDialog()
		{
			return true;
		}

		/// <summary>
		/// 对话框关闭
		/// </summary>
		/// <exception cref="NotImplementedException"></exception>
		public void OnDialogClosed()
		{
			RequestClose?.Invoke(new DialogResult(ButtonResult.No));
			//if(RequestClose != null)
			//{
			//	RequestClose(new DialogResult(ButtonResult.No));
			//}
		}

		/// <summary>
		/// 对话框打开
		/// </summary>
		/// <param name="parameters"></param>
		/// <exception cref="NotImplementedException"></exception>
		public void OnDialogOpened(IDialogParameters parameters)
		{
			Title = parameters.GetValue<string>("Title");
			P1 = parameters.GetValue<string>("para1");
			var p2 = parameters.GetValue<string>("para2");
		}
	}
}
